package com.jd.service.impl;

import com.jd.domain.Product;
import com.jd.domain.Store;
import com.jd.dto.ProuductDto;
import com.jd.mapper.ProductMapper;
import com.jd.openfegin.StoreService;
import com.jd.service.ProductService;
import com.jd.untils.AjaxResutl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper prouductMapper;
    @Autowired
    private StoreService storeService;
    @Override
    public AjaxResutl add(ProuductDto prouductDto) {
        try {
            //保存商品到product的数据库
            Product product = new Product();
            product.setName(prouductDto.getName());
            product.setPrice(prouductDto.getPrice());
            prouductMapper.add(product);
            //保存商品到厂库store
            Store store = new Store();
            store.setProductId(product.getId());
            store.setNumber(prouductDto.getNumber());
            AjaxResutl add = storeService.add(store);
            if (!add.getSuccess()){
                return add;
            }
            return new AjaxResutl();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResutl(false,"操作失败");
        }
    }
}
